package didi;

import java.io.*;
import java.util.*;

/*
 * To execute Java, please define "static void main" on a class
 *
 * If you define many classes, but you must have a class named Main and a public property.
 * The Main class should be the only public class.
 * The Main class must contain a static method (function) named "main"
 * Do not add any package, like "package main"
 *
 * The TestCase is shown below
 * Input : 1 2
 * Output : 3
 */

class Main {
    static int[] nums={5,7,7,8,8,10};
    public static void main(String[] args) {

        int low=0,high=nums.length-1;
        int target=8;
//        int a=Arrays.binarySearch(nums,5);
//        System.out.println(a);
        int firstIndex=binarySearch(low,high,target);
        if(firstIndex==-1){
            System.out.println(firstIndex);
            return;
        }
        int endIndex=0;
        //输出
        for(int i=firstIndex;i<=high;i++){
            if(nums[i]!=target){
                endIndex=i;
                break;
            }
        }
        endIndex=endIndex-1;
        System.out.println(firstIndex+","+endIndex);
    }
    public static int binarySearch(int low,int high,int target){
        int l=low,h=high;
        int mid=0;
        while(l<h){
            mid=(l+h)/2;
            if(nums[mid]>=target){
                h=mid;
            }else{
                l=mid+1;
            }
        }
        System.out.println(nums[h]);
        if(nums[h]==target)return h;
        return -1;

    }
}